<?php

declare(strict_types=1);

namespace App\Controller\Setting;


use App\Controller\BaseController;
use App\Request\Setting\AcceptVideoRequest;
use App\Request\Setting\ChangeLanguageRequest;
use App\Request\Setting\SetPriceRequest;
use App\Request\SystemVersionChannelRequest;
use App\Services\Setting\SettingService;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class SettingController extends BaseController
{

    #[Inject]
    public SettingService $settingService;


    /**
     * Note - 当前等级，下一级，当等级值和下一级值的差，当前等级值到下一等级值完成的百分比
     * DateTime 2024/8/7 19:26
     * User Admin
     * @param RequestInterface $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function getWealth()
    {
        $data = $this->settingService->getWealth();
        return $this->return($data);
    }


    /**
     * Note - 我的设置页面信息
     * DateTime 2024/8/7 19:27
     * User Admin
     * @param SystemVersionChannelRequest $request
     * @return ResponseInterface
     */
    public function mySetting(SystemVersionChannelRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $data = $this->settingService->mySetting($params);
        return $this->return($data);
    }


    /**
     * Note -   通话设置（获取价格）
     * DateTime 2024/8/12 17:38
     * User Admin
     */
    public function getPrice()
    {
        $userInfo = Context::get('user');
        $data = $this->settingService->getPrice($userInfo);
        return $this->return($data);

    }


    /**
     * Note - 通话设置（设置价格）
     * DateTime 2024/8/12 17:53
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function setPrice(SetPriceRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        $params['language'] = Context::get('language');
        $data = $this->settingService->setPrice($userInfo, $params);
        return $this->return($data);
    }


    /**
     * Note - 修改语言
     * DateTime 2024/8/12 17:53
     * User Admin
     * @param ChangeLanguageRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function changeLanguage(ChangeLanguageRequest $request)
    {
        // $request->validated();
        $params = $this->request->post();
        $request->execute($params);
        $language = $params['language'];
        $userInfo = Context::get('user');
        $this->settingService->changeLanguage($userInfo, $language);
        return $this->return();

    }


    /**
     * Note - 接受匹配开关
     * DateTime 2024/8/16 17:39
     * User Admin
     * @param AcceptVideoRequest $request
     * @return ResponseInterface
     */
    public function acceptVideo(AcceptVideoRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $uid = Context::get('user')['id'];
        $ret = $this->settingService->acceptVideo($uid, $params);
        return $this->return($ret);
    }

    public function setHideNickname()
    {
        $uid = Context::get('user')['id'];
        $status = $this->request->post('status');
        $ret = $this->settingService->setHideNickname($uid, $status);
        return $this->return();
    }
}
